package com.whh.cos.service.impl;

import com.qcloud.cos.COSClient;
import com.qcloud.cos.model.Bucket;
import com.whh.cos.service.BucketService;
import com.whh.cos.utils.CosAuth;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author huahui.wu.
 *         Created on 2018/1/16.
 */
@Service
public class BucketServiceImpl implements BucketService {

    private COSClient cosClient;

    @Override
    public List<Bucket> getBuckets() {
        cosClient = CosAuth.getCosAuth();
        return cosClient.listBuckets();
    }

    @Override
    public Bucket createBucket(String bucketName) {
        cosClient = CosAuth.getCosAuth();
        return cosClient.createBucket(bucketName);
    }

    @Override
    public void deleteBucket(String bucketName) {
        cosClient = CosAuth.getCosAuth();
        cosClient.deleteBucket(bucketName);
    }

    @Override
    public boolean headBucket(String bucketName) {
        cosClient = CosAuth.getCosAuth();
        return cosClient.doesBucketExist(bucketName);
    }
}
